<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>配置管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="layui/css/layui.css" media="all">
    <link rel="stylesheet" href="css/css.css"/>
</head>
<body>
<div class="layui-container">
    <div class="layui-btn-group demoTable">
        <button class="layui-btn" id="addproperty">添加配置</button>
    </div>
    <table id="propertiesList" lay-filter="propertiesData"></table>
</div>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script src="layui/layui.js" charset="utf-8"></script>
<script src="js/common.js" charset="utf-8"></script>
<script>
    layui.use(['table', 'layer', 'jquery', 'form'], function () {
        var table = layui.table,
                layer = layui.layer,
                $ = layui.jquery;

        table.render({
            elem: '#propertiesList'
            , url: 'property/list'
            , width: 600
            , page: true
            , limit: 10
            , method: "get"
            , cols: [
                [
                    {field: 'path',  align: 'center', title: '路径'}
                    , {field: 'data', width:200, align: 'center', title: '值'}
                    , {field: "right",  title: '操作', align: 'center', toolbar: '#barDemo'}
                ]
            ]

        });

        //监听工具条
        table.on('tool(propertiesData)', function (obj) {
            //当前行数据
            var data = obj.data;

            if (obj.event === 'del') {//删除

                layer.confirm('真的删除么', function (index) {
                    //发送删除请求
                    doAjax($, layer, 'POST', false, {"path": data.path,"data": data.data}, '/property/del', afterDel);

                    //删除成功回调函数
                    function afterDel(result) {
                        if (result.status == "200") {
                            obj.del();
                            layer.close(index);
                        } else {
                            layer.msg(result.msg);
                        }

                    }

                });

            } else if (obj.event === 'edit') {//编辑

                showPopup(layer, 2, "编辑配置", "propertyEdit", '50px', ['400px', '350px'], initEditForm);

                //弹出层成功回调函数
                function initEditForm(layero, index) {
                    $(':focus').blur();
                    var iframeWin = window[layero.find('iframe')[0]['name']];

                    //调用弹出框页面渲染表单方法给表单赋值
                    iframeWin.formRender(data);
                }
            }

        });

        //添加新用户按钮点击
        $("#addproperty").on("click", function () {
            showPopup(layer, 2, "添加配置", "propertyAdd", '50px', ['400px', '350px'], afterOpen($));
        });


    });
</script>

</body>
</html>